package org.acme;

import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.client.KubernetesClient;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.List;

/**
 * @author: Hu Shan
 * @date: 2023/3/13 15:20
 * @description: 查找某命名空间下的所有pod
 */
@Path("/pod")
public class Pods {

    private final KubernetesClient kubernetesClient;

    public Pods(KubernetesClient kubernetesClient) {
        this.kubernetesClient = kubernetesClient;
    }

    @GET
    @Path("/{namespace}")
    @Produces(MediaType.TEXT_PLAIN)
    public List<Pod> helloPods(@PathParam("namespace")String namespace) {
        return kubernetesClient.pods().inNamespace(namespace).list().getItems();
    }

}